const { app, BrowserWindow,ipcMain,dialog } = require('electron')

const dev = true

const createWindow = () => {
  const win = new BrowserWindow({
    width: dev?1350:850,
    height: 500,
    icon: './assets/icon/icon.png',
		webPreferences: {
			nodeIntegration: true,
			contextIsolation: false,
		},
    resizable: dev,
    frame: false,
    titleBarStyle: 'hidden',
  })
	if(dev){
    win.webContents.openDevTools()
  }
	ipcMain.on('file-selector', (event,properties,title,filters={ name:'所有文件', extensions: ['*'] }) => {
    dialog.showOpenDialog({
			title:title,
			properties: properties,
      filters:filters,
		}).then(result => {
			event.returnValue = result
		})
  })
	ipcMain.on('operation-window', (event,type) => {
    if(type=='min'){
      win.minimize()
    }
    if(type=='close'){
      win.close()
    }
    event.returnValue = true
  })
  win.loadFile('index.html')
}

app.whenReady().then(() => {
  createWindow()
})